﻿using System.Web;

namespace LsTool
{
    /// <summary>
    /// Http静态
    /// </summary>
    public class HttpCom
    {

        /// <summary>
        /// 获取App_Data路径
        /// </summary>
        public static string GetDataPath { get { return HttpContext.Current.Server.MapPath("~/App_Data"); } }
        /// <summary>
        /// 获取域名
        /// </summary>
        public static string GetHostUrl
        {
            get
            {
                if (HttpContext.Current != null)
                {
                    return HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Host;
                    ;
                }
                else
                {
                    return "";
                }

            }
        }


        /// <summary>
        /// 获取ip
        /// </summary>
        /// <returns></returns>
        public static string GetIp
        {
            get
            {
                var request = System.Web.HttpContext.Current.Request;
                var ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (string.IsNullOrEmpty(ip))
                {
                    ip = request.ServerVariables["REMOTE_ADDR"];
                }
                if (string.IsNullOrEmpty(ip))
                {
                    ip = request.UserHostAddress;

                }

                return ip;
            }
        }
    }
}